package com.lmt_28;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ClientReader extends Thread{
    private Socket socket;
    public ClientReader(Socket socket){
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            InputStream in = socket.getInputStream();
            DataInputStream dos = new DataInputStream(in);
            while (true){
                try{
                    String rec = dos.readUTF();
                    System.out.println(rec);
                }catch (Exception e){
                    System.out.println("自己下线了" + socket.getRemoteSocketAddress());
                    dos.close();
                    socket.close();
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
